package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Chukuxinxi;
import com.example.exception.CustomException;
import com.example.service.ChukuxinxiService;
import com.example.vo.ChukuxinxiVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("chukuxinxiService")
public class ChukuxinxiServiceImpl extends ServiceImpl<ChukuxinxiDao, Chukuxinxi> implements ChukuxinxiService {

    @Resource
    private ChukuxinxiDao chukuxinxiDao;

    public Chukuxinxi add(Chukuxinxi chukuxinxi) {
		
	   //youquchong1
        chukuxinxi.setAddtime(new Date());
        chukuxinxiDao.insert(chukuxinxi);
        return chukuxinxi;
    }
	
	
	
    public void delete(Long id) {
        chukuxinxiDao.deleteById(id);
    }
	

    public void update(Chukuxinxi chukuxinxi) {
        //youquchong2
        chukuxinxiDao.updateById(chukuxinxi);
    }
	
	public void updateByzhujian(Chukuxinxi chukuxinxi) {
        LambdaQueryWrapper<Chukuxinxi> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ObjectUtils.isNotEmpty(chukuxinxi.getBianhao()), Chukuxinxi::getBianhao,chukuxinxi.getBianhao());

        chukuxinxiDao.update(chukuxinxi, wrapper);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return chukuxinxiDao.daochuexcel();
    }

    @Override
    public Chukuxinxi findById(Integer id) {
        return chukuxinxiDao.selectById(id);
    }
	
	@Override
    public Chukuxinxi getByzhujian(String zhujian) {
        return chukuxinxiDao.getByzhujian(zhujian);
    }

    public ChukuxinxiVo findPage(ChukuxinxiVo chukuxinxiVo) {
        LambdaQueryWrapper<Chukuxinxi> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(chukuxinxiVo.getBianhao()), Chukuxinxi::getBianhao,chukuxinxiVo.getBianhao());        wrapper.like(ObjectUtils.isNotEmpty(chukuxinxiVo.getMingcheng()), Chukuxinxi::getMingcheng,chukuxinxiVo.getMingcheng());        wrapper.like(ObjectUtils.isNotEmpty(chukuxinxiVo.getLeibie()), Chukuxinxi::getLeibie,chukuxinxiVo.getLeibie());        wrapper.like(ObjectUtils.isNotEmpty(chukuxinxiVo.getKucun()), Chukuxinxi::getKucun,chukuxinxiVo.getKucun());        wrapper.like(ObjectUtils.isNotEmpty(chukuxinxiVo.getChukushuliang()), Chukuxinxi::getChukushuliang,chukuxinxiVo.getChukushuliang());        wrapper.like(ObjectUtils.isNotEmpty(chukuxinxiVo.getChukushijian()), Chukuxinxi::getChukushijian,chukuxinxiVo.getChukushijian());        wrapper.like(ObjectUtils.isNotEmpty(chukuxinxiVo.getBeizhu()), Chukuxinxi::getBeizhu,chukuxinxiVo.getBeizhu());        
		wrapper.orderByDesc(Chukuxinxi::getId);
        Page<Chukuxinxi> page = new Page<>(chukuxinxiVo.getCurrent(),chukuxinxiVo.getCurrentNum());
        chukuxinxiDao.selectPage(page,wrapper);
        List<Chukuxinxi> chukuxinxis = page.getRecords();
        chukuxinxiVo.setList(chukuxinxis);
        chukuxinxiVo.setPages(page.getPages());
        chukuxinxiVo.setTotal(page.getTotal());
        chukuxinxiVo.setCurrent(page.getCurrent());
        chukuxinxiVo.setCurrentNum(page.getSize());
        return chukuxinxiVo;
    }

    @Override
    public void deleteList(List<Chukuxinxi> list) {
        List<Integer> ids =  list.stream().map(Chukuxinxi::getId).collect(Collectors.toList());
        chukuxinxiDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
